<?php
require('config.php');

        $user_id=$_REQUEST['user_id'];
        $time=time();
		$sql="select * from `".$oto."_youhui` where end_time>'{$time}' and `begin_time`<='{$time}' and is_effect='1'";
		//file_put_contents("tsxx.txt", "\r\n".$sql."\r\n", FILE_APPEND);
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$youhui[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(isset($youhui))
		{
			for($i=0;$i<count($youhui);$i++)
			{
				$youhui_id=$youhui[$i]['id'];
				$sql="select * from `".$oto."_youhui_user_link` where youhui_id='{$youhui_id}' and u_is_effect='1' and user_id='{$user_id}'";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$youhui_user_link[$i][]=$row;//将取得的所有数据赋值给person_info数组
				}
				$sql="select * from `".$oto."_youhui_use_record` where youhui_id='{$youhui_id}' and userId='{$user_id}'";
				$result=$db->query($sql);
				while($row=$result->fetch_assoc()){
					$youhui_use_record[$i][]=$row;//将取得的所有数据赋值给person_info数组
				}
				$reco=0;
				if(isset($youhui_use_record[$i]))
				{
					for($j=0;$j<count($youhui_use_record[$i]);$j++)
					{
						if(date('Y-m-d',$youhui_use_record[$i][$j]['useTime'])==date('Y-m-d',$time))
						{
							$reco++;
						}
					}
				}
				if(!isset($youhui_user_link[$i]))
				{
					$youhui[$i]['youhui_user_link']=$reco;
				}
				else
				{
					$youhui[$i]['youhui_user_link']=$youhui_user_link[$i][0]['todayget'];
				}
			}
			echo json_encode($youhui);
		}
		else echo "[]";
		
?>